package logic

import (
	"context"
	"errors"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseReleaseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseReleaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseReleaseLogic {
	return &HouseReleaseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseReleaseLogic) HouseRelease(in *house.HouseReleaseRequest) (*house.HouseReleaseResponse, error) {
	// todo: add your logic here and delete this line
	h := mysql.House{
		HouseName:  in.HouseName,
		Address:    in.Address,
		HouseType:  in.HouseType,
		HouseFloor: in.HouseFloor,
		Price:      in.Price,
		HouseArea:  in.HouseArea,
		HouseCover: in.HouseCover,
	}
	err := h.Create()
	if err != nil {
		logx.Info("创建房源发布信息失败", err)
		return nil, errors.New("创建房源发布信息失败")
	}

	return &house.HouseReleaseResponse{
		HouseId: int64(h.ID),
	}, nil
}
